module Main where

import System.IO
import System.IO.Error
import System.Environment
import Control.Monad
import Control.Monad.Error

import FdParser
import FdEval


main = do {
	args <- getArgs;  
	case args of
        [] ->  (do {
            env <- do_init;
            do_interact env;
        });
		(filename:args) -> 
            do_execute filename;
}

do_interact env = do {
    putStr $ ">>> ";
    hFlush stdout;
    code <- getLine;
    case code of
        ":quit" ->
            return ();
        ":fd" -> (do {
            putStrLn $ _fd;
            next;
        })
        "" ->
            next;
        _ -> (do {
           result <- do_eval env (code++";"); 
           putStrLn $ "=> "++result;
           next;
        });}
    where
        next = do_interact env

do_execute fname = do {
    (withFile fname ReadMode (\ f -> do { 
        code <- hGetContents f;
        result <- do_run code;
		putStrLn $ "=> "++result;
	}));
}




--- just ...
_fd =       ""
            ++         " people wanna remember all \n"
            ++         "    what they 'd lost \n"
            ++         "      see, buddy! \n"
            ++         "  fineday is just in your memory! \n"
            ++         "  \n "
            ++         "  where we live on is just cold planets, \n"
            ++         "    cold planets \n" 
            ++         "      cycling and rolling \n"
            ++         "        forever and ever \n"
            ++         "      live and die \n"
            ++         "    forever and ever \n"
            ++         "      never across as it seems \n"
            ++         "!!! \n"
            ++         "_ come  on \n"
            ++         " I don't BEILEVE in LIES\n"
            ++         " i DONT believe IN truth\n"
            ++         " I DONT BEILEVE IN WORLDS\n"
            ++         " I DONT BEILEVE IN PEACE\n"
            ++         " plz ! \n"
            ++         " plz, make the planet warm \n"
            ++         "_ all is yours \n"
            ++         " just remember once ,\n"
            ++         " the fineday's existence \n"
